package com.tools.compass.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.preference.PreferenceManager;

public class SharedPref {

	private static SharedPref mSharedPref;
	private SharedPreferences mSharedPreferences;

	private SharedPref(Context context) {
		mSharedPreferences = PreferenceManager
				.getDefaultSharedPreferences(context);
		mSharedPreferences
				.registerOnSharedPreferenceChangeListener(new OnSharedPreferenceChangeListener() {
					@Override
					public void onSharedPreferenceChanged(
							SharedPreferences sharedPreferences, String key) {

					}
				});
	}

	public static synchronized SharedPref getInstanse(Context context) {
		if (mSharedPref == null) {
			mSharedPref = new SharedPref(context);
		}
		return mSharedPref;

	}

	public void putWidget(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt("widget", value);
		editor.commit();
	}

	public int getWidget(int defValue) {
		return mSharedPreferences.getInt("widget", defValue);
	}

	public boolean getCompassGuideShow(boolean defValue) {
		// return mSharedPreferences.getBoolean("compass_guide", defValue);
		return false;
	}

	public void putCompassGuide(boolean value) {
		Editor editor = mSharedPreferences.edit();
		editor.putBoolean("compass_guide", value);
		editor.commit();
	}

	public int getCompassDrawble(int defValue) {
		return mSharedPreferences.getInt("compass_drawble", defValue);
	}

	public void putCompassDrawble(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt("compass_drawble", value);
		editor.commit();
	}

	public int getCompassLayoutBg(int defValue) {
		return mSharedPreferences.getInt("compass_layout_bg", defValue);
	}

	public boolean putCompassLayoutBg(int value) {
		Editor editor = mSharedPreferences.edit();
		editor.putInt("compass_layout_bg", value);
		return editor.commit();
	}
}
